using System;
using System.Collections;
using System.Collections.Generic;
using Net.Server;
using Net.Share;
using Net.System;
using UnityEngine;

public class Peer : ClientPeer
{
    
}

public class Service : TcpServer<Peer>
{
    public Transform transform;
    
    protected override void StartProcessThreads()
    {
        ThreadPool = new ThreadPipelineOne<Peer>
        {
            MaxThread = 1
        };
        ThreadPool.SetProcess<Peer>(NetworkProcessing);
        ThreadPool.Init("NetworkProcessing_");
        ThreadPool.Start();
    }

    protected override void StartProcessAccept()
    {
    }

    public void Update()
    {
        AcceptUpdate(false);
        ThreadPool.Update();
    }

    [Rpc(NetCmd.SafeCallHash, 123)]
    private void RpcCall(Peer peer)
    {
        transform.Rotate(0,30,0);
        //Debug.Log("服务器回调");
        Call(peer, 123);
    }
}

public class Server : MonoBehaviour
{
    private Service service;
    public int port = 9543;
    
    // Start is called before the first frame update
    private void Start()
    {
        service = new Service();
        service.transform = transform;
        //service.AddAdapter(new Net.Adapter.SerializeAdapter3());
        service.AddAdapter(new Net.Adapter.CallSiteRpcAdapter(false));
        service.Start(port);
    }

    // Update is called once per frame
    private void Update()
    {
        service.Update();
    }

    private void OnDestroy()
    {
        service?.Close();
    }
}
